package com.umanji.user.domain;

import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Set;

import javax.persistence.AttributeOverrides;
import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToMany;
import javax.persistence.MapsId;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.NamedNativeQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.annotations.SQLUpdate;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.umanji.building.domain.PublicOfficialBuildingAdmins;
import com.umanji.generic.entity.UUIDEntity;
import com.umanji.message.domain.Messages;
import com.umanji.security.domain.Users;
import com.umanji.usedmarket.domain.UsedProducts;

@Entity
@Table(name="umanji_member")
public class Members extends UUIDEntity<Members> {

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name="USERNAME")
	private Users user;

	@OneToMany(mappedBy = "member")
	private Set<UsedProducts> usedProduct;

	// @OneToOne(mappedBy = "member")
    @ManyToMany(
        cascade = {CascadeType.PERSIST, CascadeType.MERGE},
        mappedBy = "members",
        targetEntity = PublicOfficialBuildingAdmins.class
    )
	private List<PublicOfficialBuildingAdmins> pobAdmins;

	@Column(name = "juminNum1", nullable = false)
	private Integer juminNum1;

	@Column(name = "juminNum2", nullable = false)
	private Integer juminNum2;
	
	@Column(name = "realName", nullable = false)
	private String realName;	// 실명
	
	@Column(name = "nickName", nullable = false)
	private String nickName;	// 닉네임
	
	@Column(name = "sexDistinction", nullable = false)
	private String sexDistinction;
	
	@Column(name = "emailAddress", nullable = false)
	private String emailAddress;
	
	@Column(name = "phoneNumber", nullable = false)
	private String phoneNumber;
	
	@Column(name = "birthDate", nullable = false)
	private Date birthDate;
	
	@Column(name = "profilePhoto", nullable = false)
	private String profilePhoto;

	@Transient
	private CommonsMultipartFile fileData;

	@OneToMany(mappedBy="receiver")
	@OrderBy("regDate")
	@Column(name = "receivedMessages", nullable = false)
	private Set<Messages> receivedMessages;	// 받은 쪽지

	@OneToMany(mappedBy="sender")
	@OrderBy("regDate")
	@Column(name = "sendedMessages", nullable = false)
	private Set<Messages> sendedMessages;	// 보낸 쪽지

	@Column(name = "point", nullable = false)
	private Integer point = new Integer("0");			// 포인트
	
	@Column(name = "credibility", nullable = false)
	private Integer credibility = new Integer("0");		// 신뢰도
	
	@Column(name = "cont", nullable = false)
	private Integer cont = new Integer("0");			// 콘트

	@Embedded 
	private Address address;

	protected Members() {
		// TODO Auto-generated constructor stub
	}

    public Members(Users user) {
        this.user = user;
    }

	public Set<UsedProducts> getUsedProduct() {
		return usedProduct;
	}

	public void setUsedProduct(Set<UsedProducts> usedProduct) {
		this.usedProduct = usedProduct;
	}

	public String getEmailAddress() {
		return emailAddress;
	}

	public void setEmailAddress(String emailAddress) {
		this.emailAddress = emailAddress;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getSexDistinction() {
		return sexDistinction;
	}

	public void setSexDistinction(String sexDistinction) {
		this.sexDistinction = sexDistinction;
	}

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public Address getAddress() { 
		return address; 
	}

	public void setAddress(Address address) { 
		this.address = address; 
	}

	public Users getUser() {
		return user;
	}

	public void setUser(Users user) {
		this.user = user;
	}

	public Integer getJuminNum1() {
		return juminNum1;
	}

	public void setJuminNum1(Integer juminNum1) {
		this.juminNum1 = juminNum1;
	}

	public Integer getJuminNum2() {
		return juminNum2;
	}

	public void setJuminNum2(Integer juminNum2) {
		this.juminNum2 = juminNum2;
	}

	public Date getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(Date birthDate) {
		this.birthDate = birthDate;
	}

	public String getProfilePhoto() {
		return profilePhoto;
	}

	public void setProfilePhoto(String profilePhoto) {
		this.profilePhoto = profilePhoto;
	}

	public CommonsMultipartFile getFileData()
	{
		return fileData;
	}

	public void setFileData(CommonsMultipartFile fileData)
	{
		this.fileData = fileData;
	}

	public Integer getPoint() {
		return point;
	}

	public void setPoint(Integer point) {
		this.point = point;
	}

	public Integer getCredibility() {
		return credibility;
	}

	public void setCredibility(Integer credibility) {
		this.credibility = credibility;
	}

	public Integer getCont() {
		return cont;
	}

	public void setCont(Integer cont) {
		this.cont = cont;
	}

	public void setPobAdmin(List<PublicOfficialBuildingAdmins> pobAdmins) {
		this.pobAdmins = pobAdmins;
	}

	public List<PublicOfficialBuildingAdmins> getPobAdmin() {
		return pobAdmins;
	}

	public Set<Messages> getReceivedMessages() {
		return receivedMessages;
	}

	public void setReceivedMessages(Set<Messages> receivedMessages) {
		this.receivedMessages = receivedMessages;
	}

	public Set<Messages> getSendMessages() {
		return sendedMessages;
	}

	public void setSendMessages(Set<Messages> sendedMessages) {
		this.sendedMessages = sendedMessages;
	}
}